
clear
set more off



capture confirm file "Appendix_Results/"
if _rc mkdir "Appendix_Results/"


capture confirm file "Appendix_Results/gphs/"
if _rc mkdir "Appendix_Results/gphs/"




use "Data/Big_Pandemics.dta", clear
gen pandemic=1
drop year
ren endyear year
sort year
merge 1:1 year using "Data/UKGDP.dta"
sort year
merge 1:1 year using "Data/RealRateSince1310.dta", nogen
sort year
replace pandemic=0 if pandemic==.

gen pandemic100k=cond(dead>=100000,pandemic,0)

merge 1:1 year using "Data/sdeaths.dta" , nogen
gen war_deaths = sdeaths
replace sdeaths =0 if sdeaths==.
replace sdeaths= cond(sdeaths>20000,1,0)
sort year



keep year gdp gdppc  pandemic100k UKR_real sdeaths
sort year

replace gdppc = log(gdppc)*100			/*  take log */

tsset year
gen gdpgrowth = d.gdppc


sort  year
tsset year



/********** State space specification starts here *************/

constraint 1	[pot]L.pot			= 1		/* Definitional */	
constraint 2	[pot]L.gw			= 1		/* Definitional */
constraint 3	[gw]L.gw			= 1		/* Random walk assumption */
constraint 4	[gdppc]pot			= 1		/* Definitional */


cap drop zero								/* generate zero line for figures */
gen zero = 0


/************	 State space equations	 ******************/

sspace		(pot L.pot L.gw, state noconstant noerror)		/// /* Potential Output */
			(gw L.gw, state noconstant)				/// /* Growth of potential */
			(gdppc pot, noconstant ),				/// /* Output */
			covstate(identity) constraints(1/4) difficult /*method(kdiffuse)*/ iterate(25)
			
			qui{
			/* Generate smoothed estimates of potential and growth rate */
			predict y_star if e(sample), states smethod(smooth) equation(pot)
	


			
			cap drop Zero
			gen Zero=0
			
			gen plotgdppc = gdppc/100
			gen ploty_star = y_star/100
			/**** plot full sample and post-1985 for more detail ****/
			twoway   (tsline plotgdppc if year>1311, yaxis(2) lc(blue) lw(normal) ///
			 xlab(1400(200)2000) ) ///
			(tsline ploty_star  if year>1311, yaxis(2) lc(red)  lw(normal) lp(normal) ///
			 xlab(1400(200)2000, labsize(large)) ylab(, angle(0) axis(2) labsize(large) nogrid) xtitle("Year", size(large)) ytitle("Index", axis(2) size(large)) ) ///
			, title(" ") graphregion(color(white)) plotregion(color(white)) ///
			legend(col(2) order(1 2 ) region(ls(none) col(white)) size(vlarge)  ///
			label(1 "real GDP p.c.") label(2 "trend of real GDP p.c.") ring(0) position(11) ) ///
			name(trend1,replace)  nodraw 
			
			
			
			}










graph combine trend1, ///
graphregion(color(white)) scheme(s1color) ///
rows(1) cols(1) imargin(tiny) ysize(4) xsize(8) iscale(0.75) 

graph save   Appendix_Results/gphs/FigureA1b.gph, replace
graph export Appendix_Results/FigureA1b.pdf, replace







